﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Linq;
using QuanLyKhachSan.report;
namespace QuanLyKhachSan.BaoCao
{
    public partial class frmInHoaDon_Moi_ : DevExpress.XtraEditors.XtraForm
    {
        DataClassesKhachSanDataContext db = new DataClassesKhachSanDataContext(SystemInfo.pub_ConnString); 
        public frmInHoaDon_Moi_()
        {
            InitializeComponent();
        }
        public int cttp_id, phuthu;
        private void frmInHoaDon_Moi__Load(object sender, EventArgs e)
        {
            this.filldata(); 
        }
        void filldata()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Loai");
            dt.Columns.Add("TenHang");
            dt.Columns.Add("SoLuong" , typeof(Int16));
            dt.Columns.Add("Gia", typeof(Decimal));
            dt.Columns.Add("ThanhTien", typeof(Decimal));

           
            var phong = (from p in db.CHI_TIET_THUE_PHONGs where p.CTTP_ID == cttp_id select p).Single();

            TimeSpan ngay;
            if (phong.CTTP_NGAYKT != null)
            {
                ngay = DateTime.Parse(phong.CTTP_NGAYKT.Value.ToString().Substring(0, 10)) - DateTime.Parse(phong.CTTP_NGAYBD.ToString().Substring(0, 10));

                //ngay = phong.CTTP_NGAYKT.Value.Subtract(phong.CTTP_NGAYBD).Days;  
            }
            else
            {
                ngay = DateTime.Now - DateTime.Parse(phong.CTTP_NGAYBD.ToString().Substring(0, 10));
            }

            dt.Rows.Add("Tiền phòng" , 
                phong.PHONG.P_MA, 
                ngay.TotalDays , phong.CTTP_DONGIA,
                phong.CTTP_TIENPHONG
                );


            var thucan = (from p in db.GOI_THUC_AN_NHANHs where p.CTTP_ID == cttp_id select p).ToList();
            for (int i = 0; i < thucan.Count; i++)
            {
                dt.Rows.Add("Dịch vụ",
               thucan[i].THUC_UONG_THUC_AN_NHANH.DOI_TUONG.DT_TEN,
              thucan[i].G_SL,
               thucan[i].G_DONGIA,
              thucan[i].G_SL * thucan[i].G_DONGIA
              );
            }


            var dichvu = (from p in db.SU_DUNGs where p.SD_CHITIETTPID == cttp_id select p).ToList();
            for (int i = 0; i < dichvu.Count  ; i++)
            {
                 dt.Rows.Add("Khác" , 
                 dichvu[i].DICH_VU.DV_TEN,
                 dichvu[i].SD_SL,
                 dichvu[i].SD_DONGIA,
                 dichvu[i].SD_SL * dichvu[i].SD_DONGIA
                );
            }
            rptHoaDonMoi hoadon = new rptHoaDonMoi();
            hoadon.SetDataSource(dt);
            crystalReportViewer1.ReportSource = hoadon; 
            
        }
    }
}